package com.jikexueshe.crm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.jikexueshe.crm.common.ResultVO;
import com.jikexueshe.crm.pojo.CDept;
import com.jikexueshe.crm.service.DeptService;

@Controller
@RequestMapping("dept")
public class DeptController implements BaseController<CDept>{
	
	@Autowired
	private DeptService deptService;

	
	
	@RequestMapping("save")
	@ResponseBody
	@Override
	public ResultVO save(CDept t) {
		t.setId(null);
		deptService.save(t);
		return new ResultVO(200, "增加成功");
	}
	
	
	@RequestMapping("delete")
	@ResponseBody
	@Override
	public ResultVO delete(Integer id) {
		deptService.delete(id);
		return new ResultVO(200, "删除成功");
	}

	@RequestMapping("update")
	@ResponseBody
	@Override
	public ResultVO update(CDept t) {
		Integer id = t.getId();
		if(null == id) {
			return new ResultVO(200, "没有id");
		}
		deptService.update(t);
		return new ResultVO(200, "修改成功");
	}

	@RequestMapping("list")
	@ResponseBody
	@Override
	public ResultVO select(Integer page,Integer rows,CDept t) {
		PageInfo info = deptService.select(page,rows,t);
		return new ResultVO(info.getTotal(),info.getList());
	}

	@RequestMapping("getById")
	@ResponseBody
	@Override
	public ResultVO getById(Integer id) {
		CDept byId = deptService.getById(id);
		return new ResultVO(byId);
	}

}
